/**
 * Created by baidm in 2022/4/16 on 15:26
 */
import {Axios} from "axios";

class HttpCommonService {
    constructor() {
        this.$axios = new Axios({
            baseURL: "",
            timeout: 60000,
            headers: {
                "X-Requested-With": "XMLHttpRequest",
                "content-type": "application/x-www-form-urlencoded",
            },
            withCredentials: false,
            transformRequest: [function (data, headers) {
                return data;
            }],
            transformResponse: [function (data) {
                return data;
            }],
        })

        this.$axios.interceptors.request.use(function (config) {
            return config;
        }, function (error) {
            return Promise.reject(error);
        })

        this.$axios.interceptors.response.use(function (response) {
            return response;
        }, function (error) {
            return Promise.reject(error);
        })
    }

    get(url) {
        return this.$axios.get(url)
    }

    post(url, params) {
        return this.$axios.post(url, JSON.stringify(params))
    }
}

export default new HttpCommonService()